package com.haixee.parkdemo.house_resource.controller;

import com.haixee.parkdemo.common.context.WebContextHolder;
import com.haixee.parkdemo.common.response.ResResult;
import com.haixee.parkdemo.common.response.ResUtil;
import com.haixee.parkdemo.house_resource.model.HouseResource;
import com.haixee.parkdemo.house_resource.service.HouseResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/house/resource")
public class HouseResourceController {

    @Autowired
    private HouseResourceService houseResourceService;

    @PostMapping("/add")
    public ResResult add(@RequestBody HouseResource houseResource) {


        houseResourceService.add(houseResource.getHouseName(), houseResource.getHouseAddr(), WebContextHolder.getUid());
        return ResUtil.success();
    }

    @PostMapping("/update")
    public ResResult update(@RequestBody HouseResource houseResource) {


        houseResourceService.update(houseResource.getId(), houseResource.getHouseName(), houseResource.getHouseAddr(), WebContextHolder.getUid());
        return ResUtil.success();
    }

    @GetMapping
    public ResResult getAll() {
        return ResUtil.success(houseResourceService.list());
    }
}
